/*
 * 
 */

/*
 * 
 */

	function formValidation(){
		return false;
	}
	
	function pay(e){
		var check_number = document.getElementById('check_number').value;
		var bank = document.getElementById('bank').value;
		var official_receipt_num = document.getElementById('official_receipt_num').value;
	
		if (window.XMLHttpRequest) {
			xmlhttp=new XMLHttpRequest();
		} else {
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4 && xmlhttp.status==200) {
			}
		};
		xmlhttp.open("GET","ProcessPayment.php?mode="+e+"&check_number="+check_number+"&bank="+bank+"&official_receipt_num="+official_receipt_num,true);
		xmlhttp.send();
		document.getElementById("check_number").setAttribute("disabled","disabled");
		document.getElementById("bank").setAttribute("disabled","disabled");
		document.getElementById("check").setAttribute("disabled","disabled");
		document.getElementById("cash").setAttribute("disabled","disabled");
		document.getElementById("official_receipt_num").setAttribute("disabled","disabled");
	}
	
	/* This function doesn't allow any symbols to be written on the text box*/
	function onlyAlphaNum(){
		var e = event || evt;
	    var charCode = e.which || e.keyCode;
	    if ((charCode > 31 && charCode < 48) || (charCode > 57 && charCode < 65))
	        return false;
	
	    return true;
	}
	
	/* This function checks if the date entered followed the format (mm-dd-yyyy) */
	function checkDateFormat(x){
		var validDate = /^[0-9]{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])/;
		
		var date = document.getElementsByName('samplingdate');
		var sub = document.getElementsByName('datesubmit');
		var samDate = validDate.test(date[x].value);
		var dateSub = validDate.test(sub[x].value);
		var samDateError = document.getElementsByName('samdate');
		var dateSubError = document.getElementsByName('datesub');
		
		/*var sampleSubmittedError = document.getElementById('sample');
		var sampleReceivedError = document.getElementById('samreceive');*/
		
		if (samDate == false || dateSub == false) {
			if (samDate == false){
				samDateError[x].innerHTML = "Not following date format yyyy-mm-dd";
			} 
			if (dateSub == false){
				dateSubError[x].innerHTML = "Not following date format yyyy-mm-dd";
			} 
			return false;
		} else if (samDate == true && dateSub == true) {
			return true;
		}
	}
	
	/* This function enables and disables others text box */
	function change(){
		var currentEnabled = new Array();
		currentEnabled[0] = document.addSample.othersField;
		var index = document.addSample.mainTypes.selectedIndex;
		var selectedOption = document.addSample.mainTypes.options[index].text;
		if(selectedOption == "Others..."){
			currentEnabled[0].disabled = false;
		} else {
			currentEnabled[0].disabled = true;
		}
	}
	/* This function checks if the following fields are empty */
	function checkEmpty(x){
		
		var samplingDateError = document.getElementsByName('samdate');
		var sampleSubError = document.getElementsByName('sample');
		var dateSubError = document.getElementsByName('datesub');
		var sampleRecError = document.getElementsByName('samreceived');
		
		var date = document.getElementsByName('samplingdate');
		var sign = document.getElementsByName('samplesignature');
		var sub = document.getElementsByName('datesubmit');
		var rec = document.getElementsByName('samplereceive');
		var retVal = false;
		
		if ((date[x].value == "") 
			|| (sign[x].value == "") 
			|| (sub[x].value == "") 
			|| (rec[x].value == "")) {
			if (date[x].value == "") {
				samplingDateError[x].innerHTML = "Empty Sampling Date";
			} else {
				retVal = checkDateFormat(x);
			}
			if (sign[x].value == "") {
				sampleSubError[x].innerHTML = "Empty Sample Submitted by";
			}
			if (sub[x].value == "") {
				dateSubError[x].innerHTML = "Empty Date Submitted";
			} else {
				retVal = checkDateFormat(x);
			}
			if (rec[x].value == "") {
				sampleRecError[x].innerHTML = "Empty Sample Received by";
			}
			return false;
		} else {
			retVal = checkDateFormat(x);
			return retVal;
		}
	}
	
	function checkFields(){
		countervalue = parseInt(document.getElementById("counter").value);
		var x = countervalue;
		var retVal = false;
		var flag = true;
		while(x > 0){
			retVal = checkEmpty(x-1);
			if(retVal == false){
				flag = false;
			}
			x--;
		}
		return flag;
	}
	
	function showSampleType(str,x){
		if (str=="") {
			document.getElementById("here").innerHTML="";
			return;
		} 
		if (window.XMLHttpRequest) {
			xmlhttp=new XMLHttpRequest();
		} else {
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4 && xmlhttp.status==200) {
				document.getElementById("here"+x).innerHTML=xmlhttp.responseText;
			}
		}
		xmlhttp.open("GET","libraries/GetSampleLib.php?q="+str+"&value="+x,true);
		xmlhttp.send();
	}
